package Clases.diagram.providers;

import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;

/**
 * @generated
 */
public class ClasesElementTypes extends ElementInitializers {

	/**
	 * @generated
	 */
	private ClasesElementTypes() {
	}

	/**
	 * @generated
	 */
	private static Map elements;

	/**
	 * @generated
	 */
	private static ImageRegistry imageRegistry;

	/**
	 * @generated
	 */
	private static Set KNOWN_ELEMENT_TYPES;

	/**
	 * @generated
	 */
	public static final IElementType Diagrama_79 = getElementType("Ejemplo_Tutorial.diagram.Diagrama_79"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Pointcut_1001 = getElementType("Ejemplo_Tutorial.diagram.Pointcut_1001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Advice_1002 = getElementType("Ejemplo_Tutorial.diagram.Advice_1002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Clase_1003 = getElementType("Ejemplo_Tutorial.diagram.Clase_1003"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Operador_NO_1004 = getElementType("Ejemplo_Tutorial.diagram.Operador_NO_1004"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Operador_O_1005 = getElementType("Ejemplo_Tutorial.diagram.Operador_O_1005"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Operador_Y_1006 = getElementType("Ejemplo_Tutorial.diagram.Operador_Y_1006"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Metodo_Call_1007 = getElementType("Ejemplo_Tutorial.diagram.Metodo_Call_1007"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Metodo_Execution_1008 = getElementType("Ejemplo_Tutorial.diagram.Metodo_Execution_1008"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Atributo_2001 = getElementType("Ejemplo_Tutorial.diagram.Atributo_2001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Metodo_2002 = getElementType("Ejemplo_Tutorial.diagram.Metodo_2002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Parametro_2003 = getElementType("Ejemplo_Tutorial.diagram.Parametro_2003"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ClaseSubclase_3001 = getElementType("Ejemplo_Tutorial.diagram.ClaseSubclase_3001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType PointcutContiene_3002 = getElementType("Ejemplo_Tutorial.diagram.PointcutContiene_3002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType AdviceAsociado_a_3003 = getElementType("Ejemplo_Tutorial.diagram.AdviceAsociado_a_3003"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Relacion_3004 = getElementType("Ejemplo_Tutorial.diagram.Relacion_3004"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Operador_NOOpera_sobre_3005 = getElementType("Ejemplo_Tutorial.diagram.Operador_NOOpera_sobre_3005"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Operador_OOpera_sobre_3006 = getElementType("Ejemplo_Tutorial.diagram.Operador_OOpera_sobre_3006"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Operador_YOpera_sobre_3007 = getElementType("Ejemplo_Tutorial.diagram.Operador_YOpera_sobre_3007"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Metodo_PointcutAsociado_a_3008 = getElementType("Ejemplo_Tutorial.diagram.Metodo_PointcutAsociado_a_3008"); //$NON-NLS-1$

	/**
	 * @generated
	 */
	private static ImageRegistry getImageRegistry() {
		if (imageRegistry == null) {
			imageRegistry = new ImageRegistry();
		}
		return imageRegistry;
	}

	/**
	 * @generated
	 */
	private static String getImageRegistryKey(ENamedElement element) {
		return element.getName();
	}

	/**
	 * @generated
	 */
	private static ImageDescriptor getProvidedImageDescriptor(
			ENamedElement element) {
		if (element instanceof EStructuralFeature) {
			EStructuralFeature feature = ((EStructuralFeature) element);
			EClass eContainingClass = feature.getEContainingClass();
			EClassifier eType = feature.getEType();
			if (eContainingClass != null && !eContainingClass.isAbstract()) {
				element = eContainingClass;
			} else if (eType instanceof EClass
					&& !((EClass) eType).isAbstract()) {
				element = eType;
			}
		}
		if (element instanceof EClass) {
			EClass eClass = (EClass) element;
			if (!eClass.isAbstract()) {
				return Clases.diagram.part.ClasesDiagramEditorPlugin
						.getInstance().getItemImageDescriptor(
								eClass.getEPackage().getEFactoryInstance()
										.create(eClass));
			}
		}
		// TODO : support structural features
		return null;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(ENamedElement element) {
		String key = getImageRegistryKey(element);
		ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key);
		if (imageDescriptor == null) {
			imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
		}
		return imageDescriptor;
	}

	/**
	 * @generated
	 */
	public static Image getImage(ENamedElement element) {
		String key = getImageRegistryKey(element);
		Image image = getImageRegistry().get(key);
		if (image == null) {
			ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
			image = getImageRegistry().get(key);
		}
		return image;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImageDescriptor(element);
	}

	/**
	 * @generated
	 */
	public static Image getImage(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImage(element);
	}

	/**
	 * Returns 'type' of the ecore object associated with the hint.
	 * 
	 * @generated
	 */
	public static ENamedElement getElement(IAdaptable hint) {
		Object type = hint.getAdapter(IElementType.class);
		if (elements == null) {
			elements = new IdentityHashMap();

			elements.put(Diagrama_79, Clases.ClasesPackage.eINSTANCE
					.getDiagrama());

			elements.put(Pointcut_1001, Clases.ClasesPackage.eINSTANCE
					.getPointcut());

			elements.put(Advice_1002, Clases.ClasesPackage.eINSTANCE
					.getAdvice());

			elements.put(Clase_1003, Clases.ClasesPackage.eINSTANCE.getClase());

			elements.put(Operador_NO_1004, Clases.ClasesPackage.eINSTANCE
					.getOperador_NO());

			elements.put(Operador_O_1005, Clases.ClasesPackage.eINSTANCE
					.getOperador_O());

			elements.put(Operador_Y_1006, Clases.ClasesPackage.eINSTANCE
					.getOperador_Y());

			elements.put(Metodo_Call_1007, Clases.ClasesPackage.eINSTANCE
					.getMetodo_Call());

			elements.put(Metodo_Execution_1008, Clases.ClasesPackage.eINSTANCE
					.getMetodo_Execution());

			elements.put(Atributo_2001, Clases.ClasesPackage.eINSTANCE
					.getAtributo());

			elements.put(Metodo_2002, Clases.ClasesPackage.eINSTANCE
					.getMetodo());

			elements.put(Parametro_2003, Clases.ClasesPackage.eINSTANCE
					.getParametro());

			elements.put(ClaseSubclase_3001, Clases.ClasesPackage.eINSTANCE
					.getClase_Subclase());

			elements.put(PointcutContiene_3002, Clases.ClasesPackage.eINSTANCE
					.getPointcut_Contiene());

			elements.put(AdviceAsociado_a_3003, Clases.ClasesPackage.eINSTANCE
					.getAdvice_Asociado_a());

			elements.put(Relacion_3004, Clases.ClasesPackage.eINSTANCE
					.getRelacion());

			elements
					.put(Operador_NOOpera_sobre_3005,
							Clases.ClasesPackage.eINSTANCE
									.getOperador_NO_Opera_sobre());

			elements.put(Operador_OOpera_sobre_3006,
					Clases.ClasesPackage.eINSTANCE.getOperador_O_Opera_sobre());

			elements.put(Operador_YOpera_sobre_3007,
					Clases.ClasesPackage.eINSTANCE.getOperador_Y_Opera_sobre());

			elements.put(Metodo_PointcutAsociado_a_3008,
					Clases.ClasesPackage.eINSTANCE
							.getMetodo_Pointcut_Asociado_a());
		}
		return (ENamedElement) elements.get(type);
	}

	/**
	 * @generated
	 */
	private static IElementType getElementType(String id) {
		return ElementTypeRegistry.getInstance().getType(id);
	}

	/**
	 * @generated
	 */
	public static boolean isKnownElementType(IElementType elementType) {
		if (KNOWN_ELEMENT_TYPES == null) {
			KNOWN_ELEMENT_TYPES = new HashSet();
			KNOWN_ELEMENT_TYPES.add(Diagrama_79);
			KNOWN_ELEMENT_TYPES.add(Pointcut_1001);
			KNOWN_ELEMENT_TYPES.add(Advice_1002);
			KNOWN_ELEMENT_TYPES.add(Clase_1003);
			KNOWN_ELEMENT_TYPES.add(Operador_NO_1004);
			KNOWN_ELEMENT_TYPES.add(Operador_O_1005);
			KNOWN_ELEMENT_TYPES.add(Operador_Y_1006);
			KNOWN_ELEMENT_TYPES.add(Metodo_Call_1007);
			KNOWN_ELEMENT_TYPES.add(Metodo_Execution_1008);
			KNOWN_ELEMENT_TYPES.add(Atributo_2001);
			KNOWN_ELEMENT_TYPES.add(Metodo_2002);
			KNOWN_ELEMENT_TYPES.add(Parametro_2003);
			KNOWN_ELEMENT_TYPES.add(ClaseSubclase_3001);
			KNOWN_ELEMENT_TYPES.add(PointcutContiene_3002);
			KNOWN_ELEMENT_TYPES.add(AdviceAsociado_a_3003);
			KNOWN_ELEMENT_TYPES.add(Relacion_3004);
			KNOWN_ELEMENT_TYPES.add(Operador_NOOpera_sobre_3005);
			KNOWN_ELEMENT_TYPES.add(Operador_OOpera_sobre_3006);
			KNOWN_ELEMENT_TYPES.add(Operador_YOpera_sobre_3007);
			KNOWN_ELEMENT_TYPES.add(Metodo_PointcutAsociado_a_3008);
		}
		return KNOWN_ELEMENT_TYPES.contains(elementType);
	}

}
